package com.example.cinemaorder.controller;

import com.example.cinemaorder.entity.SysBill;
import com.example.cinemaorder.entity.vo.SysBillVo;
import com.example.cinemaorder.entity.vo.UpdateMovieSaleVo;
import com.example.cinemaorder.service.SysBillService;
import com.example.cinemaorder.util.ResponseResult;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 高垚淼
 * @version 1.0
 */
@RestController
public class SysBillController {

    @Autowired
    RabbitTemplate rabbitTemplate;
    @Autowired
    SysBillService sysBillService;

    // 添加订单
    @PostMapping("/sysBill")
    public Object addBill(@Validated @RequestBody SysBillVo sysBillVo) {
        return rabbitTemplate.convertSendAndReceive("exchangetopicGetOrder","getOrder.getOrderDead",sysBillVo);
    }

    // 查询影院信息
    @GetMapping("/cinemaInfo/{id}")
    public Object getCinemaInfo(@PathVariable("id") Long id){
        return new ResponseResult(200,"查询场次信息成功",sysBillService.getCinemaInfo(id));
    }

    // 查询电影信息
    @GetMapping("/movieName/{id}")
    public Object movieName(@PathVariable("id") Long id){
        return new ResponseResult(200,"查询电影信息成功",sysBillService.movieName(id));
    }

    // 获取订单信息
    @GetMapping("/sysBill/{id}")
    public Object getBill(@PathVariable("id") Long id){
        return new ResponseResult(200,"查询订单信息成功",sysBillService.bill(id));
    }

    // 取消订单
    @PostMapping("/sysBill/cancel")
    public Object cancelBill(@RequestBody SysBillVo sysBillVo){
        return new ResponseResult(200,"查询订单信息成功",sysBillService.cancelBill(sysBillVo));
    }

//    支付订单，修改支付状态，价格
    @PostMapping("/sysBill/pay")
    public Object payBill(@RequestBody SysBill sysBill){
        sysBillService.payBill(sysBill);
        return new ResponseResult(200,"支付订单信息成功",null);
    }

//    删除超时未支付的无效订单
    @GetMapping("/sysBill/clearInvalidOrder")
    public void clearInvalidOrder(){
        sysBillService.clearInvalidOrder();
    }
}
